﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows;
using Tools.Core;
using Tools.Core.Mvvm;

namespace Tools.Modules.Navigations.ViewModels
{
    public class CodeFormatterViewModel : BindableBase,INavigationAware
    {
        private ObservableCollection<string> _formatLanguages;
        public ObservableCollection<string> FormatLanguages
        {
            get => _formatLanguages;
            set=>SetProperty(ref _formatLanguages, value);
        }
        private string _currentLanguage=string.Empty;
        public string CurrentLanguage
        {
            get=>_currentLanguage;
            set=>SetProperty(ref _currentLanguage, value);
        }
        private string _code=string.Empty;
        public string Code
        {
            get => _code;
            set => SetProperty(ref _code, value);
        }
        public DelegateCommand FormatCommand { get; private set; }
        public CodeFormatterViewModel(GlobalConfig config)
        {
            FormatLanguages = config.FormatLanguages;
            FormatCommand = new DelegateCommand(() =>
            {
                Code = Softwares.FormatCode(Code);
            },()=>Code!=string.Empty&&CurrentLanguage!=string.Empty).ObservesProperty(()=>CurrentLanguage).ObservesProperty(()=>Code);
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
        }
    }
}
